
#define GPIOA *((volatile unsigned int*)0x10000000)
#define GPIOB *((volatile unsigned int*)0x00001004)
#define UART_DR *((volatile unsigned char*)0x00001000)

#define GPIO0 *((volatile unsigned int*)0x00001008)
#define GPIO1 *((volatile unsigned int*)0x0000100C)
#define GPIO2 *((volatile unsigned int*)0x00001010)
#define RAM_START *((volatile unsigned int*)0x800004)
#define RAM_END *((volatile unsigned int*)0x1000000)
#define SECTION(x)                  __attribute__((section(x)))
void SECTION("FSymTab") puts(char*str)
{
    unsigned int i;
    for(i=0;str[i] != 0;i++)
    {
        UART_DR = str[i];
    }
}
void puts2(char*str)
{
    unsigned int i;
    for(i=0;str[i] != 0;i++)
    {
        UART_DR = str[i];
    }
}
const char hextable[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
void SECTION("FSymTab") printInt(char*str1,unsigned int data)
{
    char str2[9] = {0};
    unsigned char ch,i;
    puts(str1);
    for(i=0;i<8;i++)
    {
        ch = (unsigned char )data;
        ch = ch &0xf;
        data>>=4;
        str2[7 - i] = hextable[ch];
    }
    str2[8]=0;
    puts(str2);
    puts("\n");
}

extern unsigned int get_sp(void);
unsigned int data_test=0x55aa30;
void  irq(unsigned int irq,unsigned int *p,unsigned int sp) 
{
    unsigned int i;

    if((irq&0x20000000)==0x20000000)
    {
        printInt("error inst 0x",*p);
        printInt("addr 0x",p);
        while(1);
    }
    printInt("irq:0x",irq);
    printInt("pc:0x",p);
    printInt("sp:0x",sp);
    puts("irq1\r\n");

}

extern void set_reg(unsigned int i);
extern unsigned int get_reg(void);
extern void set_irq(unsigned int i);
int main(void)
{
    unsigned int i;
puts("mmp\r\n");
set_reg(10000); 
set_irq(0x0fffffff);
asm("ecall");

// puts("mmp\r\n");
printInt("test printint:",0x1267);
RAM_START = 0x11223344;
printInt("test psram ",RAM_START);
*((volatile unsigned short*)0x800006) = 0x7788;
printInt("test psram2 ",RAM_START);
    while(1)
    {
        for(i = 0; i<160;i++);
        GPIOA^=0xff;
        // puts("mmp\r\n");
//        GPIO0=~GPIO0;
    }
    return 0;
}